#include <stdio.h>
#include <tchar.h>
#include "stdafx.h"
#include "Frm2XYT.h"
#include <iostream>

using namespace std;
Frm2XYT::Frm2XYT(void)
{
}


Frm2XYT::~Frm2XYT(void)
{
}

int Frm2XYT::Convert2XYT(int len,int maxLen,char *input,char *output)
{
	//iterator,data length, total converted byte value,x,y,theta,quality
	int i=0,dataLengthValue=0,totalConvertedValue=0,x=0,y=0,theta=0,quality=0;

	//temporary output data array, stores biometric data lenght value,stores biometric data
	char tempOutputDataArray[4096],lengthArray[9],tempBioData[700];

	char *tempOutputDatArrayPointer=tempOutputDataArray;
	char * hexValues=&lengthArray[0];
	char *hex2LastValue=&lengthArray[4];
	char *dataArray=&tempBioData[0];

	for (i = 0; i < 4; i++)
	{
		sprintf(hexValues+i*2,"%02X",input[9+i]);
	}
	
	dataLengthValue=Convert2Int(hex2LastValue);
	
	for (i = 0; i < dataLengthValue; i++)
	{
		sprintf(dataArray+i*2,"%02X",input[50+i]);
		x=Convert2Int(dataArray[i+0]);
		y=Convert2Int(dataArray[i+1]);
		theta=Convert2Int(dataArray[i+2]);
		quality=Convert2Int(dataArray[i+3]);

		sprintf(tempOutputDatArrayPointer+i*4,"%d %d %d %d \n",x,y,theta,quality);
		
		totalConvertedValue+=strlen(tempOutputDataArray)+1;
	}

	memcpy(output,tempOutputDataArray,maxLen);

	return totalConvertedValue;
}

int Frm2XYT::Convert2Int(char *hexValuesInput)
{
	char *p=hexValuesInput;
	int a=(int)strtol(p,NULL,16);
	return a;
}

int Frm2XYT::Convert2Int(char hexValuesInput)
{
	char *p=&hexValuesInput;
	int a=(int)strtol(p,NULL,16);
	return a;
}

